﻿#region 命名空间

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;

#endregion

namespace Sharp.Domain.PlatformBoundedContext.ModelConfigurations
{
    /// <summary>
    ///     Represents the entity type configuration for the <see cref="User" /> entity.
    /// </summary>
    public partial class UserTypeConfiguration : EntityTypeConfiguration<User>
    {
        #region 构造函数

        /// <summary>
        ///     Initializes a new instance of <c>CustomerTypeConfiguration</c> class.
        /// </summary>
        public UserTypeConfiguration()
        {
            HasKey(c => c.Id);
             
            Property(c => c.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(c => c.UserName)
                .IsRequired()
                .HasMaxLength(50);
            Property(c => c.Password)
                .IsRequired().IsUnicode(false)
                .HasMaxLength(42);
            Property(c => c.Email)
                .IsOptional().IsUnicode(false)
                .HasMaxLength(80);

            Property(c => c.LastLogonIp)
           .IsOptional().IsUnicode(false)
           .HasMaxLength(128);

            this.HasRequired(t => t.Profile).WithRequiredPrincipal(x => x.User).WillCascadeOnDelete(false);

            HasMany(t => t.Groups)
            .WithMany(t => t.Users)
            .Map(m =>
            {
                m.ToTable("Platform_UserGroup");
                m.MapLeftKey("GroupId");
                m.MapRightKey("UserId");
            });
        }

        #endregion
    }
}